package com.gistmap.ntdc.web;

import com.gistmap.ntdc.persistence.domain.Address;
import com.gistmap.ntdc.response.Result;
import com.gistmap.ntdc.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zhangran
 * @date 2018/12/26
 */
@RestController
@RequestMapping("/address")
public class AddressController {

    @Autowired
    private AddressService addressService;

    @PostMapping
    public Result add(AddressService.AddressForm form){
        return new Result().success(addressService.add(form));
    }

    @DeleteMapping
    public void delete(Long id){
        addressService.delete(id);
    }

    @PutMapping
    public Result update(AddressService.AddressForm form) {
        return new Result().success(addressService.update(form));
    }

    /**
     * 登陆用户的所有地址
     * @return
     */
    @GetMapping("/list")
    public Result list(){
        return new Result().success(addressService.list());
    }

    /**
     * 查询用户的默认地址
     * @return
     */
    @GetMapping
    public Result defaultAddress(){
        return new Result().success(addressService.getDefaultAddress());
    }



}
